package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Result;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {

    @Autowired
    DeptService deptService;

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("根据ID查询, id: {}" , id);
        return Result.success(deptService.getById(id));
    }
    @GetMapping
    public Result list() {
        log.info("查询部门列表");
        return Result.success(deptService.list());
    }
    @DeleteMapping
    public Result delete(Integer id) {
        return Result.success(deptService.delete(id));
    }

    @PutMapping
    public Result update(@RequestBody Dept dept) {
        log.info("修改部门, dept: {}" , dept);
        return Result.success(deptService.update(dept));
    }

    @PostMapping
    public Result add(@RequestBody Dept dept) {
        log.info("新增部门, dept: {}" , dept);
        return Result.success(deptService.add(dept));
    }


}
